/**
 * Copyright (c) 2018-2022, NXOS Development Team
 * SPDX-License-Identifier: Apache-2.0
 * 
 * Contains: Init aarch64 Qemu platfrom 
 * 
 * Change Logs:
 * Date           Author            Notes
 * 2021-10-1      JasonHu           Init
 */

#include <nxos_mini.h>
#include <drivers/direct_uart.h>
#include <base/smp.h>
#include <base/log.h>
#include <base/irq.h>
#include <arch/gicv2.h>
#include <arch/arm_local_reg.h>

#define NX_LOG_LEVEL NX_LOG_INFO
#define NX_LOG_NAME "INIT"
#include <base/debug.h>

#include <page_zone.h>

NX_INTERFACE NX_Error NX_HalPlatformInit(NX_UArch coreId)
{
    NX_HalDirectUartInit();
    NX_LOG_I("Hello, QEMU aarch64!");

    /* init int controller */
    gic_init(0, GIC_V2_DISTRIBUTOR_BASE, GIC_V2_CPU_INTERFACE_BASE);

    /* init memory */
    NX_HalPageZoneInit();

    return NX_EOK;
}

NX_INTERFACE NX_Error NX_HalPlatformStage2(void)
{
    NX_LOG_I("stage2!");

    NX_HalDirectUartStage2();
    return NX_EOK;
}
